package com.simple.gateway.center.config.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.simple.gateway.center.basedata.common.SimpleGatewayConstants;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.util.Date;

/**
 * 项目: simple-gateway-core
 *
 * 功能描述: mybatisplus自动填充字段
 *
 * @author: WuChengXing
 *
 * @create: 2023-08-07 14:16
 **/
@Configuration
public class AutoFillFieldConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("isDeleted", SimpleGatewayConstants.NOT_DELETED, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
